#pragma once

#include <iostream>
#include <vector>
#include <string.h>
#include "out.hpp"
#include <stdint.h>

static int n_10(uint8_t n)
{
	int i = 1;
	for (int j = 0; j < n; j++)
	{
		i *= 10;
	}
	return i;
}

std::vector<int> OptionUser(){
	PrintHelp();
	std::vector<int> result;
	//人物选择
	PrintStd("请选择2~4个角色：1.钱夫人 2.阿土伯 3.孙小美 4.金贝贝，可自由排序");
	// TODO
	// may create wrong
	char read = 0;
	int8_t st[100];
	int count=0;
	while (true)
	{
		count = 0;
		read = getchar();
		while (read != '\n')
		{
			st[count++] = read - '0';
			read = getchar();
		}

		if (count > 4 || count < 2)
		{
			PrintStd("请输入正确格式");
			continue;
		}
		uint8_t flag = 0;
		for (int i = 0; i < count; i++)
		{
			if (st[i] < 1 || st[i] > 9)
				flag = 1;
		}
		for (int i = 0; i < count - 1; i++)
		{
			if (st[i] == st[i + 1])
				flag = 1;
		}
		for (int i = 0; i < count - 2; i++)
		{
			if (st[i] == st[i + 2])
				flag = 1;
		}
		for (int i = 0; i < count - 3; i++)
		{
			if (st[i] == st[i + 3])
				flag = 1;
		}
		if (flag)
		{
			PrintStd("请输入正确格式");
			continue;
		}
		else
			break;
	}
	for (int i = 0; i < count; i++){
		result.push_back(st[i]);
	}
	return result;
}
int OptionMoney(){
	//开局资金选择
	char read = 0;
	int8_t st[100];
	int count=0;
	int i_fund=0;
	printf("请输入启动资金，范围：1000~50000\n");
	while (true)
	{
		count = 0;
		i_fund = 0;
		read = getchar();
		while (read != '\n')
		{
			st[count++] = read - '0';
			read = getchar();
		}

		uint8_t flag = 0;
		for (int i = 0; i < count; i++)
		{
			if (st[i] < 0 || st[i] > 9)
				flag = 1;
		}
		for (uint8_t i = 0; i < count; i++)
		{
			i_fund += st[i] * n_10(count - i - 1);
			if (i_fund < 1000 || i_fund > 50000)
				flag = 1;
		}
		if (i_fund==0) {
			flag=1;
		}
		if (flag)
		{
			printf("请输入正确格式\n");
			continue;
		}
		else
			break;
	}
	return i_fund;
}
